﻿using RedmineToolBar.Redmine.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RedmineToolBar.Utility
{
    public static class RibbonUtility
    {

        public static void SetEnable(RibbonStatus status)
        {
            var ribbon = Globals.Ribbons.Ribbon1;

            switch (status)
            {
                case RibbonStatus.NOT_CONFIGURED:
                    ribbon.btnConfig.Enabled = true;
                    ribbon.btnSetupQuery.Enabled = false;
                    ribbon.btnUpdate.Enabled = false;
                    ribbon.btnStatus.Image = Properties.Resources.Disconnected_32;
                    ribbon.btnStatus.Label = Properties.Resources.btnStatusNotConnectedLabel;
                    ribbon.btnStatus.Enabled = false;
                    ribbon.lblServer.Label = "server: ";
                    ribbon.lblQuery.Label = "query: ";
                    ribbon.lblLastUpdate.Label = "Last Update: ";
                    ribbon.lblServer.Visible = false;
                    ribbon.lblQuery.Visible = false;
                    ribbon.lblLastUpdate.Visible = false;
                    ribbon.separator1.Visible = false;

                    break;
                case RibbonStatus.CONFIGURED:
                    ribbon.btnConfig.Enabled = true;
                    ribbon.btnSetupQuery.Enabled = true;
                    ribbon.btnUpdate.Enabled = false;
                    ribbon.btnStatus.Image = Properties.Resources.Disconnected_32;
                    ribbon.btnStatus.Label = Properties.Resources.btnStatusNotConnectedLabel;
                    ribbon.btnStatus.Enabled = false;
                    RedmineConfigurationBuilder rb = new RedmineConfigurationBuilder();
                    var conf = rb.GetRedmineCongfiguration();
                    ribbon.lblServer.Label = "server:" + conf.Url;
                    ribbon.lblServer.Visible = true;
                    ribbon.separator1.Visible = true;

                    break;
                case RibbonStatus.CONNECTED_TO_QUERY:
                    ribbon.btnConfig.Enabled = true;
                    ribbon.btnSetupQuery.Enabled = true;
                    ribbon.btnUpdate.Enabled = true;
                    ribbon.btnStatus.Image = Properties.Resources.Connected_32;
                    ribbon.btnStatus.Label = Properties.Resources.btnStatusConnectedLabel;
                    ribbon.btnStatus.Enabled = true;
                    RedmineConfigurationBuilder rb1 = new RedmineConfigurationBuilder();
                    var conf1 = rb1.GetRedmineCongfiguration();

                    ribbon.lblServer.Label = "server: " + conf1.Url;
                    ribbon.lblQuery.Label = "query: " + conf1.QueryName;
                    ribbon.lblLastUpdate.Label ="Last Update: "+ conf1.LastUpdate.ToString();
                    ribbon.lblServer.Visible = true;
                    ribbon.lblQuery.Visible = true;
                    ribbon.lblLastUpdate.Visible = true;
                    ribbon.separator1.Visible = true;

                    break;
                default:
                    break;
            }
        }
    }

    public enum RibbonStatus
    {

        NOT_CONFIGURED,
        CONFIGURED,
        CONNECTED_TO_QUERY

    }

}
